/**
 * Created by thinkl on 2017/6/24.
 */
$(function () {
    var add_id = getQueryString('id');
    $.post('/address/get_address', {address_id: add_id}, function (data) {
        var l = JSON.parse(data);
        var res = l.result;
        $('input[name=person]').val(res.name);
        $('input[name=phone]').val(res.phone);
        $('input[name=add_province]').val(res.add_province);
        $('input[name=add_city]').val(res.add_city);
        $('input[name=add_district]').val(res.add_district);
        $('input[name=add_detail]').val(res.add_detail);
        if (res.is_default) {
            $('input[name=add_is_default]').attr('checked', true)
        }
    });
});
function add_mod_save() {
    var add_id = getQueryString('id');
    var person = $('input[name=person]').val();
    var phone = $('input[name=phone]').val();
    var add_province = $('input[name=add_province]').val();
    var add_city = $('input[name=add_city]').val();
    var add_district = $('input[name=add_district]').val();
    var add_detail = $('input[name=add_detail]').val();
    var add_is_default = false;
    if ($('input[name=add_is_default].checked')) {
        add_is_default = true;
    }
    if (!(/^1[3|4|5|8][0-9]\d{4,8}$/.test(phone))) {
        alert("不是完整的11位手机号或者正确的手机号前七位");
        return false;
    }
    $.post('/address/modify_address', {
        address_id: add_id,
        name: person,
        phone: phone,
        add_province: add_province,
        add_city: add_city,
        add_district: add_district,
        add_detail: add_detail,
        add_is_default: add_is_default
    }, function (data) {
        var l = JSON.parse(data);
        alert(l.message)
    })
}
function back_add_list() {
    location.href = '/static/address_list/address_list.html'
}